package com.example.controller;

import com.example.entity.Menu;
import com.example.entity.vo.ResponseData;
import com.example.service.IMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author CDHong.it
 * @since 2023-06-27
 */
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private IMenuService menuService;

    @GetMapping("menu_role_id")
    public ResponseData menuByRoleId(HttpSession session){
        Integer roleId = (Integer) session.getAttribute("roleId");
        List<Menu> menus = menuService.menuByRoleId(roleId);
        Map<String,Object> map = new HashMap<>();
        map.put("userName",session.getAttribute("userName"));
        map.put("menus",menus);
        return ResponseData.data(map);
    }

}
